package com.mengxinya.ys.spider.zhihu;

import java.util.*;
import java.security.MessageDigest;

public class MyTest {
    public static void main(String[] args) throws Exception {
        String source = "101_3_3.0+/api/v4/members/hasmart/answers?include=data%5B*%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cattachment%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Cexcerpt%2Cpaid_info%2Creaction_instruction%2Cis_labeled%2Clabel_info%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%2Cis_recognized%3Bdata%5B*%5D.vessay_info%3Bdata%5B*%5D.author.badge%5B%3F%28type%3Dbest_answerer%29%5D.topics%3Bdata%5B*%5D.author.vip_info%3Bdata%5B*%5D.question.has_publishing_draft%2Crelationship&offset=20&limit=20&sort_by=created+\"ACDQzxaGshSPTvIRVL7fJ10_vAGYr4UqMZ8=|1648357912\"";
        String x_zse_96 = get_x_zse_96(source);
        System.out.println(x_zse_96);
    }

    public static String get_x_zse_96(String source) throws Exception {
        String md5_str = getMd5(source) + '\u0000';
        String f_str = "RuPtXwxpThIZ0qyz_9fYLCOV8B1mMGKs7UnFHgN3iDaWAJE-Qrk2ecSo6bjd4vl5";
        List<String> result_arr = new ArrayList<String>();
        int p = 0;
        for (int i = md5_str.length() - 2; i >= 0; i--) {
            if (i % 3 == 0) {

                p += 1;
                p = p - 4 > 0 ? p - 4 : p;
                int a = (int) md5_str.charAt(i + 2);
                int b = (int) md5_str.charAt(i + 1);
                int c = (int) md5_str.charAt(i);
                int m;
                if (p == 1) {
                    m = m1(a, b, c);
                } else if (p == 2) {
                    m = m2(a, b, c);
                } else if (p == 3) {
                    m = m3(a, b, c);
                } else {
                    m = m4(a, b, c);
                }
                result_arr.add(String.valueOf(f_str.charAt(m % 64)));
                result_arr.add(String.valueOf(f_str.charAt((m >> 6) % 64)));
                result_arr.add(String.valueOf(f_str.charAt((m >> 12) % 64)));
                result_arr.add(String.valueOf(f_str.charAt((m >> 18) % 64)));
            }
        }
        StringBuilder result = new StringBuilder();
        for (String s : result_arr) {
            result.append(s);
        }
        return result.toString();
    }

    public static String getMd5(String source) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(source.getBytes());
        byte[] digest = md.digest();
        StringBuilder sb = new StringBuilder();
        for (byte b : digest) {
            sb.append(String.format("%02x", b & 0xff));
        }
        return sb.toString();
    }

    public static int m1(int a, int b, int c) {
        return ((a ^ 42) | (b << 8)) | (c << 16);
    }

    public static int m2(int a, int b, int c) {
        return (a | ((b ^ 42) << 8)) | (c << 16);
    }

    public static int m3(int a, int b, int c) {
        return (a | (b << 8)) | ((c ^ 42) << 16);
    }

    public static int m4(int a, int b, int c) {
        return (a | (b << 8)) | (c << 16);
    }
}